package com.cax.module.enterprise.controller;

import com.cax.module.enterprise.domain.dto.EnterpriseCertificateDTO;
import com.cax.module.enterprise.domain.dto.EnterpriseCertificateDelDTO;
import com.cax.module.enterprise.domain.dto.EnterpriseCertificateQueryDTO;
import com.cax.module.enterprise.domain.dto.EnterpriseCertificateUpdateDTO;
import com.cax.module.file.domain.FileType;
import com.cax.module.file.domain.vo.File2VO;
import com.cax.module.file.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.Api;
import com.cax.module.enterprise.service.EnterpriseCertificateService;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import com.cax.module.enterprise.domain.vo.EnterpriseCertificateVO;
import com.cax.common.core.domain.Result;
import javax.validation.constraints.NotNull;
import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.multipart.MultipartFile;


@Slf4j
@RestController
@Api(tags = "企业证书")
@RequestMapping("/enterpriseCertificate")
@Validated
public class EnterpriseCertificateController {
    /**
     * 企业证书表 Service
     */
    @Autowired
    public EnterpriseCertificateService enterpriseCertificateService;

	@Autowired
	private FileService fileService;

    @GetMapping("/getByName/noAuth")
    @ApiOperation(value = "通过企业名精准匹配查询", notes = "")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "name", value = "企业名称", required = true, dataType = "String"),
	})
	public Result<List<EnterpriseCertificateVO>> getByName(
			@RequestParam(name = "name") String name
	) {
		List<EnterpriseCertificateVO> result = enterpriseCertificateService.getByName(name);
		return Result.ok(result);
	}

    @GetMapping("/getPage")
    @ApiOperation(value = "分页查询", notes = "")
	public Result<Page<EnterpriseCertificateVO>> getByPage(
		@Validated EnterpriseCertificateQueryDTO dto
	) {
		Page<EnterpriseCertificateVO> result = enterpriseCertificateService.getPage(dto);
		return Result.ok(result);
	}

	@GetMapping("/list/noAuth")
	@ApiOperation(value = "列表（无权限）", notes = "")
	public Result<Page<EnterpriseCertificateVO>> getList(
			@Validated EnterpriseCertificateQueryDTO dto
	) {
		dto.setPageSize(5000);
		Page<EnterpriseCertificateVO> result = enterpriseCertificateService.getPage(dto);
		return Result.ok(result);
	}

    @GetMapping("/getByKey")
    @ApiOperation(value = "通过主键查询", notes = "")
    @ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "主键id", required = true, dataType = "int"),
	})
	public Result<EnterpriseCertificateVO> getByKey(
			@NotNull(message = "参数id不能为空")Integer id
	) {
		EnterpriseCertificateVO result = enterpriseCertificateService.getByKey(id);
		return Result.ok(result);
	}

	@PostMapping("/add")
    @ApiOperation(value = "添加", notes = "")
	public Result<Integer> add(
		@RequestBody @Validated EnterpriseCertificateUpdateDTO dto
	) {
		Integer result = enterpriseCertificateService.add(dto);
		return Result.ok(result);
	}

	@PostMapping("/upd")
    @ApiOperation(value = "通过主键修改", notes = "")
	public Result<String> upd(
		@RequestBody @Validated EnterpriseCertificateUpdateDTO dto
	) {
		enterpriseCertificateService.upd(dto);
		return Result.ok();
	}


	@PostMapping("/upload")
	@ApiOperation(value = "上传文件", notes = "")
	public Result<File2VO> upload(
			@RequestParam(value = "file") MultipartFile file
	) {
		File2VO result = fileService.upload(FileType.TypeEnum.FILE_TYPE_3.getCode(),file);
		return Result.ok(result);
	}
	@PostMapping("/del")
	@ApiOperation(value = "删除传id", notes = "")
	public Result<String> del(
			@RequestBody @Validated EnterpriseCertificateDelDTO dto
	) {
		enterpriseCertificateService.del(dto.getId());
		return Result.ok();
	}

}

